#!/usr/bin/env bash
#
#    Linie - Install Internet Explorer on Linux
#
#    Copyright (C) 2010 Raghu Kaippully <raghu.kb@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

export LINIE_VERSION="0.3"

# Discover linie installation directory
cd $(dirname "$0")
export LINIE=$(pwd)

# Init variables
export CLEAN_IE7=0
export CLEAN_IE8=0
export CLEAN_ALL=0
export INSTALL_IE7=0
export INSTALL_IE8=0
export INSTALL_FLASH=0
export CREATE_DESKTOP_ICON=1
export CREATE_MENU_ICON=1

export BASEDIR=${HOME}/.linie
export BINDIR=${HOME}/bin
export DOWNLOADDIR=${BASEDIR}/downloads

# Locale is hardcoded to en_US for now
export IE_LOCALE="EN-US"

# Import generic functions
. ${LINIE}/lib/functions.sh

export LOGLEVEL=${LOG_INFO}

# Parse command line parameters
while [ $# -gt 0 ]; do
	case "$1" in
		--clean-ie7)		export CLEAN_IE7=1; shift;;
		--clean-ie8)		export CLEAN_IE8=1; shift;;
		--clean-all)		export CLEAN_ALL=1; shift;;
		--install-ie7)		export INSTALL_IE7=1; shift;;
		--install-ie8)		export INSTALL_IE8=1; shift;;
		--log-debug)		export LOGLEVEL=${LOG_DEBUG}; shift;;
		--log-info)		export LOGLEVEL=${LOG_INFO}; shift;;
		--log-warning)		export LOGLEVEL=${LOG_WARNING}; shift;;
		--log-error)		export LOGLEVEL=${LOG_ERROR}; shift;;
		--help|-h)		lib/help.sh; exit 0;;
		--version)
			echo "Linie-${LINIE_VERSION}"
			exit 0;;
		*)
			echo "ERROR: Invalid option $1"
			echo "Run linie --help for more information"
			exit 1;;
	esac
done

# Check dependencies
check_wine
check_winetricks
check_wget
check_md5sum

if [ ${INSTALL_IE7} == 0 -a ${INSTALL_IE8} == 0 -a ${CLEAN_IE7} == 0 -a ${CLEAN_IE8} == 0 -a ${CLEAN_ALL} == 0 ]; then
	log_error "You must specify one of --install-ie7 or --install-ie8. Try $0 --help for help."
	exit 1
fi

# Perform any clean up as needed
do_cleanup

# IE7
if [ ${INSTALL_IE7} == 1 ]; then
	. lib/ie7.sh
fi

# IE8
if [ ${INSTALL_IE8} == 1 ]; then
	echo "IE 8 installation is not yet implemented."
fi
